package com.leoman.dao;

import com.leoman.entity.CompanyUserGain;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * CompanyUserGainDao
 * Created by 涂奕恒 on 2016/11/2 0002 上午 11:02.
 */
public interface CompanyUserGainDao extends JpaRepository<CompanyUserGain, Integer>, JpaSpecificationExecutor<CompanyUserGain> {

    @Query("select a from CompanyUserGain a where a.companyUser.id = ?1 and (a.updateTime is not null and a.content = '充值') or (a.content <> '充值') group by a.recordDate order by a.recordDate desc")
    Page<CompanyUserGain> iPageByUserId(Integer companyUserId, Pageable pageable);

    @Query("select a from CompanyUserGain a where a.companyUser.id = ?1 and a.recordDate = ?2 order by a.createTime desc")
    List<CompanyUserGain> findListByRecordDate(Integer companyUserId, String recordDate);

    @Query("select a from CompanyUserGain a where a.companyUser.id = ?1 and a.createTime >= ?2 and a.createTime <= ?3 and a.content like ?4")
    List<CompanyUserGain> findListByParams(Integer companyUserId, Long startTime, Long endTime, String content);
}